//
//  SettingViewController.swift
//  Eternity
//
//  Created by cll12_12 on 2016/12/8.
//  Copyright © 2016年 ZhengWei. All rights reserved.
//

import UIKit

class SettingViewController: BaseViewController {

    // MARK: - life cycle
    override func viewDidLoad() {
        super.viewDidLoad()

        initBaseLayout()
        layoutPageSubviews()
        createUI()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    // MARK: - private method
    func initBaseLayout() {
        self.view.addSubview(setTableView)
    }
    
    func layoutPageSubviews() {
        setTableView.snp.makeConstraints { (make) in
            make.edges.equalTo(self.view).inset(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
        }
    }
    
    func createUI() {
        initNavItem(controller: self, imageName: "nav_back_n", highlitedImageName: "nav_back_h", selectedImageName: "", isLeft: true)
        self.view.backgroundColor = UIColor(hexString: "#E5E5E5")
        self.title = "设置"
    }
    
    // MARK: - setters and getters 
    var _setTableView: UITableView!
    var setTableView: UITableView {
        if _setTableView == nil {
            _setTableView = UITableView(frame: CGRect.zero, style: .grouped)
            _setTableView.backgroundColor = UIColor(hexString: "#E5E5E5")
            _setTableView.delegate = self
            _setTableView.dataSource = self
            _setTableView.register(SettingCell.self, forCellReuseIdentifier: "SettingCell")
        }
        return _setTableView
    }
    

}

extension SettingViewController: UITableViewDelegate, UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return 2
        } else if section == 1 {
            return 3
        }
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let string  = "SettingCell"
        
        let cell = tableView.dequeueReusableCell(withIdentifier: string, for: indexPath) as! SettingCell
        
        let dataSource = [["关于我们", "帮助中心"], ["版本信息", "免责声明", "去评分"]]
        cell.configUI(content: dataSource[indexPath.section][indexPath.row])
        if indexPath.section == 1 && indexPath.row == 0 {
            cell.isVersion = true
        } else {
            cell.isVersion = false
        }
        
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 44
    }
    
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 16
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1
    }

}
